package info.motteke.qjdbc.column.variable;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public final class ByteArrayVariable extends Variable {

    private InputStream is = null;

    public ByteArrayVariable(){

    }

    public ByteArrayVariable(byte[] bytes){
        is = new ByteArrayInputStream(bytes);
    }

    public ByteArrayVariable(InputStream is){
        this.is = is;
    }

    public void is(byte[] bytes){
        is = new ByteArrayInputStream(bytes);
    }

    public void is(InputStream is){
        this.is = is;
    }

    @Override
    void putValue(PreparedStatement pstmt, int index) throws SQLException {
        if(is == null){
            throw new IllegalStateException();
        }

        pstmt.setBinaryStream(index, is);
        is = null;
    }

}
